import { getButtonSettings } from '@/config/button'
export const crudOptions = (vm) => {
  return {
    pageOptions: {
      compact: true
    },
    options: {
      tableType: 'vxe-table',
      rowKey: true, // 必须设置，true or false
      rowId: 'id',
      height: '100%', // 表格高度100%, 使用toolbar必须设置
      highlightCurrentRow: false

    },
    rowHandle: {
      fixed: 'right',
      view: false,
      width: 230,
      edit: {
        thin: true,
        text: '申请通过',
        size: 'mini',
        icon: '',
        disabled (_, context) {
          return context.status !== 1
        }
      },
      remove: false,
      dropdown: {
        atLeast: 1,
        size: 'mini',
        text: '操作' // 按钮文字
      },
      custom: [{
        text: ' 查看租户信息',
        type: 'warning',
        size: 'mini',
        order: 1,
        emit: 'selectDomainInfo',
        disabled (_, context) {
          return !(context.client && context.status === 4)
        }
      }, {
        text: ' 申请拒绝',
        type: 'warning',
        size: 'mini',
        emit: 'examineRefuse',
        disabled (_, context) {
          return context.status !== 1
        }
      }]
    },
    indexRow: { // 或者直接传true,不显示title，不居中
      title: '序号',
      align: 'center',
      width: 100
    },

    viewOptions: {
      componentType: 'form'
    },
    formGroup: { // 表单分组
      type: 'collapse', // tab暂未实现
      accordion: false,
      groups: { // 分组
        base: { // 分组key
          title: '申请信息', // 分组标题
          disabled: true, // 禁止展开或收起
          // disabled(context){return true} //可以传一个方法
          show: true, // 是否显示
          // show(context){return true} //可以传一个方法
          icon: 'el-icon-goods', // 分组标题前的图标
          columns: ['name', 'appellation', 'phone', 'status', 'create_datetime'] // 该组内包含的字段列表
        },
        examine: { // 分组key
          title: '审核信息', // 分组标题
          disabled: true, // 禁止展开或收起
          // disabled(context){return true} //可以传一个方法
          show: true, // 是否显示
          // show(context){return true} //可以传一个方法
          icon: 'el-icon-goods', // 分组标题前的图标
          columns: ['schema_name', 'domain', 'package_manage', 'trial_cut_off_time'] // 该组内包含的字段列表
        }
      }
    },
    formOptions: {
      defaultSpan: 12, // 默认的表单 span
      width: '900px',
      saveButtonText: '申请通过',
      saveButtonType: 'success'
    },
    columns: [
      {
        title: 'ID',
        key: 'id',
        show: false,
        width: 70,
        form: {
          disabled: true
        }
      }, {
        title: '公司名称',
        key: 'name',
        width: 180,
        search: {
          disabled: false,
          component: {
            disabled: false,
            props: {
              clearable: true
            }
          }
        },
        form: {
          component: {
            disabled: true
          }
        },
        type: 'input'
      }, {
        title: '称呼',
        key: 'appellation',
        minWidth: 180,
        search: {
          disabled: false,
          component: {
            disabled: false,
            props: {
              clearable: true
            }
          }
        },
        form: {
          component: {
            disabled: true
          }
        },
        type: 'input'
      }, {
        title: '联系手机号',
        key: 'phone',
        type: 'input',
        width: 120,
        search: {
          disabled: false,
          component: {
            disabled: false
          }
        },
        form: {
          component: {
            disabled: true
          },
          itemProps: {
            class: { yxtInput: true }
          }
        }
      }, {
        title: '租户标识',
        key: 'schema_name',
        sortable: true,
        width: 100,
        search: {
          disabled: true
        },
        show: false,
        type: 'input',
        form: {
          rules: [ // 表单校验规则
            { required: true, message: '租户标识必填项' },
            { min: 1, max: 63, message: '长度在 1 到 63 个字符', trigger: 'blur' },
            { trigger: ['change', 'blur'], pattern: /^[_a-zA-Z0-9]{1,63}$/, message: '租户标识的字符串无效' }
          ],
          component: {
            placeholder: '请输入租户标识',
            props: {
              clearable: true
            }
          },
          itemProps: {
            class: { yxtInput: true }
          }
        }
      }, {
        title: '域名',
        key: 'domain',
        width: 160,
        search: {
          disabled: false,
          component: {
            placeholder: '请输入域名',
            props: {
              clearable: true
            }
          }
        },

        type: 'input',
        form: {
          rules: [ // 表单校验规则
            { required: true, message: '域名必填项' },
            { min: 1, max: 253, message: '长度在 1 到 253 个字符', trigger: 'blur' },
            {
              trigger: ['change', 'blur'],
              pattern: /^[a-zA-Z0-9][-a-zA-Z0-9]{0,62}(\.[a-zA-Z0-9][-a-zA-Z0-9]{0,62})+\.?$/,
              message: '域名的字符串无效'
            }
          ],
          component: {
            placeholder: '请输入域名',
            props: {
              clearable: true
            }
          },
          itemProps: {
            class: { yxtInput: true }
          }
        }
      }, {
        title: '试用套餐',
        key: 'package_manage',
        type: 'selector-table',
        dict: {
          cache: false, // 表单的dict可以禁用缓存
          url: '/api/tenant/package_manage/?status=True',
          value: 'id', // 数据字典中value字段的属性名
          label: 'name' // 数据字典中label字段的属性名
        },
        width: 160,
        search: {
          disabled: false
        },
        form: {
          rules: [ // 表单校验规则
            { required: true, message: '试用套餐必填项' }
          ],
          component: {
            span: 12,
            placeholder: '请选择试用套餐',
            elProps: {
              tableConfig: {
                pagination: true,
                multiple: false,
                columns: [
                  {
                    prop: 'name',
                    label: '套餐名称'
                  }, {
                    prop: 'description',
                    label: '套餐说明'
                  }
                ]
              }
            }
          },
          itemProps: {
            class: { yxtInput: true }
          }
        }
      },
      {
        title: '当前状态',
        key: 'status',
        type: 'select',
        width: 120,
        dict: {
          data: getButtonSettings([{ label: '待审核', value: 1 }, { label: '审核通过', value: 2 }, { label: '审核拒绝', value: 3 }, { label: '租户创建完成', value: 4 }])
        },
        search: {
          disabled: false,
          component: {
            disabled: false
          }
        },
        form: {
          component: {
            disabled: true
          },
          itemProps: {
            class: { yxtInput: true }
          }
        }
      },
      {
        title: '试用天数',
        key: 'trial_cut_off_time',
        width: 90,
        type: 'number',
        form: {
          value: 7,
          itemProps: {
            class: { yxtInput: true }
          },
          component: {
            props: {
              min: 1
            }
          },
          rules: [ // 表单校验规则
            { required: true, message: '试用天数必填项' }
          ]
        }
      },
      {
        title: '申请时间',
        key: 'create_datetime',
        width: 160,
        search: {
          disabled: true,
          width: 240,
          component: { // 查询框组件配置，默认根据form配置生成
            name: 'el-date-picker',
            props: {
              type: 'daterange',
              'range-separator': '至',
              'start-placeholder': '开始',
              'end-placeholder': '结束',
              valueFormat: 'yyyy-MM-dd'
            }
          }
        },
        form: {
          component: {
            disabled: true
          },
          itemProps: {
            class: { yxtInput: true }
          }
        },
        type: 'datetime'
      }
    ]
  }
}
